package com.volunteer.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.volunteer.entity.Activity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 活动Mapper接口
 */
@Mapper
public interface ActivityMapper extends BaseMapper<Activity> {

    /**
     * 统计所有已完成活动的服务时长总和
     */
    @Select("SELECT COALESCE(SUM(TIMESTAMPDIFF(HOUR, start_time, end_time)), 0) " +
            "FROM t_activity " +
            "WHERE status = 3")
    Long sumServiceHours();
    
    /**
     * 查询最新活动
     * @param limit 限制数量
     * @return 活动列表
     */
    @Select("SELECT id, title, status, create_time as createTime " +
            "FROM t_activity " +
            "ORDER BY create_time DESC " +
            "LIMIT #{limit}")
    List<Map<String, Object>> findLatestActivities(@Param("limit") int limit);
}
